<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/webjars/jquery/3.7.1/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
</head>
<body>
<%
//    String数组中的元素
    String[] fruits={"apple","orange","grape","banana"};
%>
<div class="container mt-3">
    <h4>String数组中的元素：</h4>
    <form action="c_foreach.jsp">
        <c:forEach var="name" items="<%=fruits %>" varStatus="loop">
            <div class="form-check">
                <input type="checkbox" class="form-check-input" id="${loop.count}" name="ocheckbox" value="${name}" />
                <label class="form-check-label" for="${loop.count}">${name}</label>
            </div>
        </c:forEach>
        <button type="submit" class="btn btn-primary mt-3">提交</button>
    </form>
    <p>
        我喜欢的水果是：<br/>
        <c:forEach var="selectedFruit" items="${paramValues.ocheckbox}">
            ${selectedFruit}<br/>
        </c:forEach>
    </p>
</div>
<hr/>
<%
    //    HashMap集合中的元素
    Map userMap=new HashMap();
    userMap.put("1","Tom");
    userMap.put("2","Make");
    userMap.put("3","Lina");
%>
<div class="container mt-3">
    <h4>HashMap集合中的元素：</h4>
    <form action="c_foreach.jsp" method="post">
        <select class="form-select" aria-label="Default select example" name="uname">
            <c:forEach var="entry" items="<%=userMap %>">
                <option value="${entry.key}">${entry.value}</option>
            </c:forEach>
        </select>
        <button type="submit" class="btn btn-primary mt-3">提交</button>
    </form>
    <p>我的英文名是：${param.uname}</p>
</div>
<hr/>
<%
//    ArrayList集合（指定迭代范围和步长）
    ArrayList colorsList=new ArrayList();
    colorsList.add("red");
    colorsList.add("yellow");
    colorsList.add("blue");
    colorsList.add("green");
    colorsList.add("black");
%>
<div class="container mt-3">
    <h4>ArrayList集合：</h4>
    <form action="c_foreach.jsp">
        <c:forEach var="color" items="<%=colorsList%>" begin="1" end="3" step="2" varStatus="loop">
            <div class="form-check">
                <input type="radio" class="form-check-input" id="${loop.index}" name="optradio" value="${color}">
                <label class="form-check-label" for="${loop.index}">${color}</label>
            </div>
        </c:forEach>
        <button type="submit" class="btn btn-primary mt-3">提交</button>
    </form>
    <p>我喜欢的颜色是：${param.optradio}</p>
</div>
<hr/>

</body>
</html>
